#include <iostream>
#include <string>
#include <vector>

using namespace std;

int n, ans;
string s, a;
vector<char> stk;

void dfs(int i) {
	// --- pop
	if (!stk.empty()) {
		a.push_back(stk.back());
		if (a.size() == n)
			cout << a << '\n', ++ans;
		stk.pop_back();
		dfs(i);
		stk.push_back(a.back());
		a.pop_back();
	}
	// --- push
	if (i < n) {
		stk.push_back(s[i]);
		dfs(i + 1);
		stk.pop_back();
	}
}

int main() {
	cout << "Please enter the in-stack "
	     "sequence:\n>>> ";
	// e.g. ABCED
	cin >> s;
	n = s.size();
	dfs(0);
	cout << "Totally " << ans << " sequences.\n";
	return 0;
}
